package cc.wsyw126.java.nowcoder.sword_offer;


/**
 * Created by Administrator on 2017/4/17.
 * 孩子们的游戏(圆圈中最后剩下的数)
 */
public class LastRemaining_Solution {
    public int LastRemaining_Solution(int n, int m) {
        if(n<=0 || m <=0)return -1;
        int i,last=0;
        for(i=2;i<=n;i++){
            last=(last+m)%i;
        }
        return last;
    }

    public static void main(String[] args) {
        LastRemaining_Solution lastRemaining_solution = new LastRemaining_Solution();
        int i = lastRemaining_solution.LastRemaining_Solution(4, 3);
        System.out.println("i = " + i);
    }
}
